/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.cef.command;

import cef.command.Command;
import cef.command.CommandException;
import coalescent.cef.event.CheckPhylogenyEvent;
import coalescent.data.K69Data;
import coalescent.phylogeny.PhylogenyAlgo;

/**
 * Checks if an instance of K69Data has phylogeny or not.
 *
 * @author Susanta Tewari
 * @version 1.0 Dec 8, 2010
 */
@SuppressWarnings("TypeMayBeWeakened")
public class CheckPhylogenyCommand extends Command<CheckPhylogenyEvent> {

    /** cmd-output. true, if data has phylogeny */
    private boolean phylogeny;

    public CheckPhylogenyCommand(final CheckPhylogenyEvent event) {
        super(event);
    }

    @Override
    public void executeImpl() throws CommandException {

        final PhylogenyAlgo phylogenyAlgo = getEvent().getPhylogenyAlgorithm();
        final K69Data data                = getEvent().getK69Data();

        phylogeny = phylogenyAlgo.isPhylogeny(data);
    }

    /**
     * @return {@code true} if the data is phylogeny; {@code false} otherwise
     */
    public boolean isPhylogeny() {

        checkCmdFinished();

        return phylogeny;
    }
}
